package com.test.mooan.labama.activity_fragment_boom;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.TextView;

import com.test.mooan.labama.R;
import com.test.mooan.labama.activity_fragment_boom.base_boom.BaseActivity_boom;
import com.test.mooan.labama.utils_boom.Threadutils_boom;
import com.test.mooan.labama.utils_boom.http_boom.HttpManager_boom;
import com.test.mooan.labama.view_boom.widget_boom.BoomEditText;
import com.test.mooan.labama.view_boom.widget_boom.TitleView_boom;

import java.util.ArrayList;


public class ServiceFeedbackActivity_boom extends BaseActivity_boom {

    private String type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_feedback_boom);
        pageTag = "SERVICE_FEEDBACK";
        init();
    }

    private void init(){

        TitleView_boom titleView = findViewById(R.id.activity_service_feedback_view_title);
        setBackBtn_boom(titleView.getBackIb());

        ArrayList<TextView> typeTvs = new ArrayList<TextView>(){{
            add(findViewById(R.id.activity_service_feedback_tv_product_suggestion));
            add(findViewById(R.id.activity_service_feedback_tv_app_bugs));
            add(findViewById(R.id.activity_service_feedback_tv_payment_issues));
            add(findViewById(R.id.activity_service_feedback_tv_others));
        }};

        for (TextView typeTv1:typeTvs){
            typeTv1.setOnClickListener(v -> {
                for (TextView typeTv2:typeTvs){
                    if (typeTv1==typeTv2){
                        typeTv2.setBackgroundResource(R.drawable.ic_round_corner_blue_boom_17dp);
                        typeTv2.setTextColor(getColor(R.color.white));
                        type = typeTv2.getText().toString();
                    }else {
                        typeTv2.setBackgroundResource(R.drawable.ic_border_blue_boom_1dp_round_corner_trans_17dp);
                        typeTv2.setTextColor(getColor(R.color.blue_boom));
                    }
                }
            });
        }

        BoomEditText inputEt = findViewById(R.id.activity_service_feedback_et_input);
        Button submitBtn = findViewById(R.id.activity_service_feedback_btn_submit);
        inputEt.stEventWord(pageTag+"_FEEDBACK_INPUT");

        submitBtn.setOnClickListener(v -> {
            String input = inputEt.getText().toString();
            if (TextUtils.isEmpty(type)||TextUtils.isEmpty(input)) {
                showToast_boom(getString(R.string.input_tip));
                return;
            }
            HttpManager_boom.getInstance().submitServiceFeedback(type,input);
        });

    }

    public void onSubmitServiceFeedback(){
        showToast_boom(getString(R.string.submit_success));
        Threadutils_boom.getInstance().postDelay(this::onBackPressed,1000);
    }

}